package com.hao.wms.mvc;

import com.hao.wms.domain.Supplier;
import com.hao.wms.query.SupplierQueryObject;
import com.hao.wms.service.ISupplierService;
import com.hao.wms.util.RequiredPermission;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

import java.io.IOException;

public class SupplierAction extends BaseAction{
	/**
	 * 
	 */
	private ISupplierService supplierService;
	
	
	private Supplier supplier = new Supplier();
	
	public Supplier getSupplier() {
		return supplier;
	}
	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}
	private SupplierQueryObject queryObject = new SupplierQueryObject();
	
	
	public SupplierQueryObject getQueryObject() {
		return queryObject;
	}
	public void setQueryObject(SupplierQueryObject queryObject) {
		this.queryObject = queryObject;
	}
	public void setSupplierService(ISupplierService supplierService) {
		this.supplierService = supplierService;
	}
	@InputConfig(methodName = "input")
	@RequiredPermission(value="供应商列表")
	public String execute() {
		putContext(PAGERESULT, supplierService.query(queryObject));
		
		return LIST;
	}
	@RequiredPermission(value="新增/修改供应商")
	public String input() {
		if(supplier.getId()!=null) {
			supplier = supplierService.get(supplier.getId());
		}
		return INPUT;
	}
	@RequiredPermission(value="修改供应商")
	public String saveOrUpdate() {
		try {
			if(supplier.getId()!=null) {
                supplierService.update(supplier);
                addActionMessage("修改成功");
            }else {
                supplierService.save(supplier);
                addActionMessage("保存成功");
            }
		} catch (Exception e) {
			e.printStackTrace();
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	public void prepareSave(){
		if(supplier.getId()!=null) {
			supplier = supplierService.get(supplier.getId());
			
		}
	}
	@RequiredPermission(value="删除供应商")
	public String delete() throws IOException{
		supplierService.delete(supplier);
		putResponseText("删除成功");
		return NONE;
	}
	
	

}
